home *** CD-ROM | disk | FTP | other *** search
- package sub_arctic.lib;
-
- import sub_arctic.constraints.std_function;
- import sub_arctic.output.drawable;
-
- /**
- * A simple container class that sizes itself to fit its children (plus an
- * optional border) then optionally draws a rectangle around its extent.
- *
- * @author Scott Hudson
- */
- public class shrink_wrap_container extends base_parent_interactor {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Space left at the right and bottom of our children */
- protected int _border = 0;
-
- /**
- * Space left at the right and bottom of our children.
- * @return int size of the border.
- */
- public int border() {return _border;}
-
- /**
- * Set space left at the right and bottom of our children.
- * @param int bv new size of the border.
- */
- public void set_border(int bv)
- {
- if (bv!=_border) {
- _border = bv;
- setup_constraints();
- }
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Flag bit position for flag indicating whether to draw the border. */
- protected static final int DRAW_BORDER = FIRST_FREE_FLAG;
-
- /**
- * Are we currently drawing the border rectangle. We store the indicator
- * for this in the interactor flags at the DRAW_BORDER bit position.
- * @return boolean indicating if we currently draw the border.
- */
- public boolean draw_border()
- {
- return flag_is_set(DRAW_BORDER);
- }
-
- /**
- * Set whether we draw a rectangle at our border.
- * @param boolean v new value indicating whether we draw the border.
- */
- public void set_draw_border(boolean v)
- {
- if (flag_is_set(DRAW_BORDER) != v)
- {
- set_flag_bit(DRAW_BORDER, v);
- damage_self();
- }
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Set constraints corresponding to current border value. These
- * constraints make our size large enough to cover the most outlying
- * child object (plus the current border on the right and bottom).
- */
- protected void setup_constraints()
- {
- /* set constraints on w/h to match max of children */
- set_w_constraint(std_function.offset(MAX_CHILD.X2(), border()));
- set_h_constraint(std_function.offset(MAX_CHILD.Y2(),border()));
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Full constructor.
- * @param int x x position of the container.
- * @param int y y position of the container.
- * @param int bd size of the border.
- * @param boolean draw_bord whether we draw a bounding rectangle.
- */
- public shrink_wrap_container(int x, int y, int bd, boolean draw_bord)
- {
- super(x,y);
- set_flag_bit(DRAW_BORDER, draw_bord);
- _border=bd;
- /* note: don't call the set functions here, they check to see if
- * the value is different and if not they don't do anything. This
- * not desirable since we need to FORCE one computation of the
- * constraints the first time.
- */
- setup_constraints();
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Draw the object's current appearance. This draws the children
- * and then the optional border rectangle.
- *
- * @param drawable d the surface we draw on.
- */
- protected void draw_self_local(drawable d)
- {
- /* let superclass draw any children we have */
- super.draw_self_local(d);
-
- /* optionally draw our border */
- if (flag_is_set(DRAW_BORDER))
- d.drawRect(0,0,w()-1,h()-1);
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-